package cn.tedu.oop2;

/**
 * @author: Dsi
 * @date: 2021/11/9 17:03
 * @description:该类用于完成汽车的设计案例
 */
public class DesignCar {
    public static void main(String[] args) {
        Car c=new Car();
        System.out.println(c.getColor());
        c.stat();
        c.stop();
        //c.swim();//报错，父类对象不能使用子类的特有功能
        BWM b=new BWM();
        System.out.println(b.color);
        System.out.println(b.getColor());//null
        b.stat();//重写的用重写的
        b.stop();//没重写用父类的

        Car c2=new TSL();
//        System.out.println(c2.color);//父类color被封装
        System.out.println(c2.getColor());//null
        c2.stop();






    }
}
class Car{
    //定义封装car的成员变量
    private String brand;
    private String color;
    private int id;
    private double price;

    public void stat(){
        System.out.println("开车了");
        //stop();
    }
    public void stop(){
        System.out.println("停车了");
    }

    public String getBrand() {
        return brand;
    }
    public void setBrand(String brand) {
        this.brand = brand;
    }
    public String getColor() {
        return color;
    }
    public void setColor(String color) {
        this.color = color;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
}
class BWM extends Car{
    String color="子类color";
    @Override
    public void stat() {
        System.out.println("子类重写的stat方法");
    }
}
class TSL extends Car{
    @Override
    public void stop() {
        System.out.println("子类TSL的stop重写");
    }
    String color="子类color02";
    public void swim(){
        System.out.println("子类TSL的特有方法");
    }
}